package code._15network.udp.v1;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Service {
    public static void main(String[] args) throws IOException {
        DatagramSocket datagramSocket = new DatagramSocket(9999);
        byte[] bytes = new byte[1024];
        DatagramPacket recivePacket = new DatagramPacket(bytes, 0, bytes.length);
        System.out.println("receive before");
        datagramSocket.receive(recivePacket);

        byte[] data = recivePacket.getData();
        int offset = recivePacket.getOffset();
        int length = recivePacket.getLength();
        String msg = new String(data, offset, length);
        System.out.println(msg);
        datagramSocket.close();

    }
}
